{% extends "base_generic.html" %}

{% block content %}
    <h1>作者详情</h1>
    <p><strong>姓名：</strong>{{ author.first_name }} {{ author.last_name }}</p>
    <p><strong>出生日期：</strong>{{ author.date_of_birth|date:"Y-m-d" }}</p>
    <p><strong>逝世日期：</strong>{% if author.date_of_death %}{{ author.date_of_death|date:"Y-m-d" }}{% else %}无{% endif %}</p>
    <p><strong>简介：</strong>{{ author.biography|linebreaks }}</p>  {# 假设模型有 biography 字段 #}

    <h2>相关书籍</h2>
    <ul>
    {% for book in author.book_set.all %}  {# 关联书籍，假设 Author 和 Book 是一对多关系 #}
        <li><a href="{% url 'book-detail' book.pk %}">{{ book.title }}</a></li>
    {% empty %}
        <li>该作者暂无关联书籍</li>
    {% endfor %}
    </ul>
{% endblock %}

{% block sidebar %}
   {{ block.super }}

  {% if author %}  {# 首先确保 author 对象存在 #}
    {% if perms.catalog.change_author or perms.catalog.delete_author %}
      <hr>
      <ul class="sidebar-nav">
        {% if perms.catalog.change_author %}
          <li><a href="{% url 'author-update' author.id %}">Update author</a></li>
        {% endif %}
        {% if perms.catalog.delete_author and not author.book_set.exists %}
          <li><a href="{% url 'author-delete' author.id %}">Delete author</a></li>
        {% endif %}
      </ul>
    {% endif %}
  {% endif %}
{% endblock %}